package com.hdax.dm.ribbitMQ.controller;

import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/rabbit")
public class RabbitMQController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping(path = "/add")
    public String add(@RequestParam("orderNo") String orderNo){
        rabbitTemplate.convertAndSend("dm_order_exchange","dm.order",orderNo,
                message -> {
                    //设置持久化
                    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    //过期时间
//                    message.getMessageProperties().setExpiration(60000*15+"");
                    message.getMessageProperties().setExpiration("10000");
                    return message;
                });
//        rabbitTemplate.convertAndSend("dm_seat_dlx_exchange","dm.seat",orderNo
               /* ,message -> {
                    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    return message;
                }
                );*/
        return "success";
    }
}
